package service;

import entity.Student;
import mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService{
    @Autowired
    private StudentMapper studentMapper;


    public Student login(String stuId, String password) throws Exception {
        Student student = getStudentById(stuId);
        if(student!=null && student.getStuPassword().equals(password)){
            return  student;
        }
        return null;
    }

    public List<Student> getAllStudent() throws Exception {
        return studentMapper.getAllStudent();
    }

    public Student getStudentById(String stuId) throws Exception {
        return studentMapper.getStudentById(stuId);
    }

    public int addStudent(Student student) throws Exception {
        return studentMapper.addStudent(student);
    }

    public int updateStudent(Student student) throws Exception {
        return studentMapper.updateStudent(student);
    }

    public int deleteStudentById(String stuId) throws Exception {
        return studentMapper.deleteStudentById(stuId);
    }
}
